import { reactive } from 'vue'

export function useTable() {
    const gridOptions = reactive<any>({
        border: true,
        columnConfig: {
            resizable: true,
        },
        columns: [
            { slots: { checkbox: 'checkbox_cell', header: 'checkbox_header' }, type: 'checkbox', width: 60 },
            { field: 'fangh', title: '房号' },
            { field: 'dongbh', title: '栋' },
            { field: 'louc', title: '楼层' },
            { field: 'zujjg', title: '租金' },
            { field: 'huxxx', title: '所属户型' },
            { field: 'xiangmmc', title: '所属项目' },
            { field: 'suosqy', title: '所属企业' },
            { slots: { default: 'shangjspzt' }, title: '上架审批状态', width: 120 },
            { field: 'xiangmdz', title: '项目地址' },
            { field: 'CreatedName', title: '创建人' },
            { field: 'CreatedTime', title: '创建时间', width: 150 },
            { fixed: true, slots: { default: 'operate' }, title: '操作', width: 300 },
        ],
        data: [],
        editConfig: {
            mode: 'row',
            showStatus: true,
            trigger: 'manual',
        },
        height: 530,
        keepSource: true,
        loading: false,
        pagerConfig: {
            currentPage: 1,
            enabled: true,
            pageSize: 10,
            pageSizes: [10, 20, 50, 100, 200, 500],
            total: 0,
        },
        showOverflow: true,
    })

    const btns = [
        {
            label: '房源详情',
            text: true,
            value: 1,
        },
        {
            label: '审批详情',
            text: true,
            value: 2,
        },
        {
            label: '审批',
            text: true,
            value: 3,
        },
        {
            label: '驳回',
            text: true,
            value: 4,
        },
    ]

    const searchBtns = [
        {
            label: '全部',
            value: 'all',
        },
        {
            label: '审批中',
            value: 'approval',
        },
        {
            label: '通过',
            value: 'pass',
        },
        {
            label: '驳回',
            value: 'reject',
        },
    ]

    const useFilter = (form: any) => {
        const arr: any = []
        for (const key in form) {
            if (Object.prototype.hasOwnProperty.call(form, key)) {
                if (form[key] !== undefined && form[key] !== null && form[key] !== '') {
                    arr.push({
                        filed: key,
                        value: form[key],
                    })
                }
            }
        }
        return arr
    }

    return { btns, gridOptions, searchBtns, useFilter }
}
